import {Dimensions, Platform} from 'react-native'

const {width, height} = Dimensions.get('window');

export const SCREEN_WIDTH = width;
export const SCREEN_HEIGHT = height;
export const STATUSBAR_HEIGHT = 20;
export const ISIPHONE_X = (Platform.OS === 'ios' && SCREEN_HEIGHT === 812 && SCREEN_WIDTH === 375);
export const TABBAR_HEIGHT_NORMAL = 49;
export const TABBAR_HEIFHT = ISIPHONE_X ? TABBAR_HEIGHT_NORMAL + STATUSBAR_HEIGHT : 49;
export const NAVBAR_HEIFHT = ISIPHONE_X ? 88 : 64;

export const urlReg = new RegExp('(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]', 'g');

export const kAuthorization = 'Authorization';
export const kContentType = 'Content-Type';


const patchPostMessageFunction = function () {
    const originalPostMessage = window.postMessage;

    const patchedPostMessage = function (message, targetOrigin, transfer) {
        originalPostMessage(message, targetOrigin, transfer);
    };

    patchedPostMessage.toString = function () {
        return String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage');
    };

    window.postMessage = patchedPostMessage;
};

export const patchPostMessageJsCode = '(' + String(patchPostMessageFunction) + ')();';


